﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity.ModelConfiguration;
using CSP.Model.CSP;
using System.ComponentModel.DataAnnotations;

namespace CSP.DataAccess.Mapping
{
    public class RateStatisticMap : EntityTypeConfiguration<RateStatistic>
    {
        public RateStatisticMap()
        {
            // Primary Key
            this.HasKey(t => new { t.ToUserName, t.CreditRating, t.OneWeekCount, t.OneMonthCount, t.SixMonthCount, t.SixMonthAgoCount });

            // Properties
            this.Property(t => t.ToUserName)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.OneWeekCount)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.OneMonthCount)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.SixMonthCount)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.SixMonthAgoCount)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            // Table & Column Mappings
            this.ToTable("RateStatistics");
            this.Property(t => t.ToUserName).HasColumnName("ToUserName");
            this.Property(t => t.CreditRating).HasColumnName("CreditRating");
            this.Property(t => t.OneWeekCount).HasColumnName("OneWeekCount");
            this.Property(t => t.OneMonthCount).HasColumnName("OneMonthCount");
            this.Property(t => t.SixMonthCount).HasColumnName("SixMonthCount");
            this.Property(t => t.SixMonthAgoCount).HasColumnName("SixMonthAgoCount");
            this.Property(t => t.TotalCount).HasColumnName("TotalCount");
        }
    }
}
